/*
 * Relay.cpp
 *
 *  Created on: Feb 5, 2012
 *      Author: xum
 */

#include "Relay.h"
#include "Arduino.h"
#include "Streaming.h"

Relay::Relay() {
//	this->state = OFF_STATE;
}

Relay::Relay(int port) {
	this->port = port;
	pinMode(port, OUTPUT);
	turnOff();
}

boolean Relay::getState() const {
	return state;
}
boolean Relay::isOn() const {
	if (state==ON_STATE) {
		return true;
	}
	else{
		return false;
	}
}

void Relay::setState(boolean state2) {
	state = state2;
	if (state) {
		digitalWrite(port, HIGH);
	}
	else{
		digitalWrite(port, LOW);
	}
}

void Relay::turnOn(){
	state = ON_STATE;
	digitalWrite(port, LOW);
}

void Relay::turnOff(){
	state = OFF_STATE;
	digitalWrite(port, HIGH);
}

